package com.dlry.serviceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dlry.db.NotificationRepository;
import com.dlry.entity.DlNotification;

@Service
@Transactional
public class NotificationServiceImpl implements NotificationService {

	private NotificationRepository notificationRepository;

	@Autowired
	public NotificationServiceImpl(NotificationRepository notificationRepository) {
		this.notificationRepository = notificationRepository;
	}

	public Page<DlNotification> findAllPage(Integer page, Integer row) {
		Sort sort = new Sort(Direction.DESC, new String[] { "toped", "updatetime" });
		Pageable pageable = new PageRequest(page, row, sort);
		Page<DlNotification> notifications = notificationRepository.findAll(pageable);
		return notifications;
	}

	public void save(DlNotification notification) {
		notificationRepository.save(notification);
	}

	public void update(DlNotification notification) {
		notificationRepository.save(notification);
	}

	public DlNotification findOne(Long nId) {
		DlNotification notification = notificationRepository.findOne(nId);
		return notification;
	}

	public void delete(Long nId) {
		notificationRepository.delete(nId);
	}

	public Long count() {
		return notificationRepository.count();
	}


}
